package jhh09wxu.globalgadgets.ejb.session;

import java.util.Date;
import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import jhh09wxu.globalgadgets.ejb.entity.*;

@Stateless
@Remote(CustomerSession.class)
public class CustomerSessionBean implements CustomerSession, java.io.Serializable {

    @PersistenceContext
    private EntityManager entityManager;
    private static final long serialVersionUID = 1;

    public List<Customer> findCustomers(String nickname) {
        Query q = this.entityManager.createQuery("SELECT c FROM Customer c WHERE c.nickname='"+nickname+"'");
        return ((List<Customer>) q.getResultList());
    }

    public void registerCustomer(String nickname, String firstname, String lastname, String address, String password, String country, Date vip) {
        Customer customer = new Customer();
        customer.setAddress(address);
        customer.setCountry(country);
        customer.setFirstname(firstname);
        customer.setLastname(lastname);
        customer.setNickname(nickname);
        customer.setPassword(password);
        customer.setVip(vip);
        this.entityManager.persist(customer);
    }
}
